import { TweenMax,TimelineMax,Power0 } from './tween/index.js';
/**
 * 
 * @param {*} sprite 
 * @param {*} time 时间单位秒 
 * @param {*} target 
 * @param {*} repeat 
 * @param {*} callback 
 */
exports.moveTween = function(sprite,time,target,repeat=0,callback){
  var tween = new TweenMax(sprite,time, {
      x: target.x,
      y: target.y,
      repeat,
      yoyo:false,
      ease:Power0.easeNone,
      onComplete:() => { if(callback) callback(sprite)}
  });
}
/**
 * 获得配置的颜色编码
 */
exports.getColorStr = function(color){
  let colorArr = color.split(',');
  let r = parseInt(colorArr[0].replace(/[^0-9]+/ig,""));
  let g = parseInt(colorArr[1].replace(/[^0-9]+/ig,""));
  let b = parseInt(colorArr[2].replace(/[^0-9]+/ig,""));
  let a = parseFloat(colorArr[3].replace(/[^0-9.]+/ig,""));
  let rStr = r.toString(16);
  if(rStr.length < 2) rStr = '0' + rStr;
  let gStr = g.toString(16);
  if(gStr.length < 2) gStr = '0' + gStr;
  let bStr = b.toString(16);
  if(bStr.length < 2) bStr = '0' + bStr;

  let colorStr = rStr + gStr + bStr;
  // console.log("color:",r,g,b,a,colorStr);
  return [colorStr,a];
}

exports.getFormatTime = function(time){
  if(time == 0) return  '00:00';
  let second = time % 60;
  second = second>9?'' + second : '0'+second;
  let minute = Math.floor( time / 60 );
  minute = minute>9?'' + minute: '0'+minute;
  return minute + ':' + second;
}

exports.Version = function (curV,reqV){
    var arr1=curV.split('.');
    var arr2=reqV.split('.');
    //将两个版本号拆成数字 
    var minL= Math.min(arr1.length,arr2.length);  
    var pos=0;        //当前比较位
    var diff=0;        //当前为位比较是否相等
    
    //逐个比较如果当前位相等则继续比较下一位
    while(pos<minL){
        diff=parseInt(arr1[pos])-parseInt(arr2[pos]);  
        if(diff!=0){  
          break;  
        } 
        pos++;                  
    }
    
    if (diff>0) {
        console.log('新版本')
        return false;
    }else if (diff==0) {
        console.log('稳定版')
        return false;
    }else{
        console.log('旧版本')
        return true;
  }
}